import {GET, POST} from "../api";
import apiUrl from "../config/apiUrls";
import {clearSessionStorage, notify} from "../utils/commonScript.js";
import router from "../router/router.js";
export const actions = {

    /**
     * 获取登录用户信息
     * @param commit
     * @param state
     * @param dispatch
     * @returns {Promise<*>}
     */
    getUser ({commit, state, dispatch}) {
        return GET(apiUrl.userInfo).then(res => {
            if(res.data) {
                if(!res.data.vip) {
                    clearSessionStorage();
                    router.push({
                        path: '/login'
                    })
                    notify('会员过期，请联系客服', 'error')
                } else {
                    sessionStorage.setItem('baseInfo', JSON.stringify(res.data))
                    commit('setBaseInfo', res.data)
                }

            }
        })
    },
}
